/**
 * 
 */
package com.geekteam.geometrychess.handler.request;

import java.util.List;

import com.geekteam.geometrychess.board.GameBoard;
import com.geekteam.geometrychess.extension.ChessExtension;
import com.geekteam.geometrychess.utils.Commands;
import com.geekteam.geometrychess.utils.Constants;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

/**
 * @author MtRol
 *
 */
public class LobbyRequestHandler extends BaseRequestHandler{

	@Override
	public void handleClientRequest(User user, ISFSObject object) {
		mExtension = (ChessExtension) this.getParentExtension();
		List<Room> roomList = mExtension.getParentZone().getRoomListFromGroup(Constants.DEFAULT_GROUP_ROOM);
		mResultObject = new SFSObject();
		
		for(Room room: roomList){
			if(room.isGame()){
				SFSObject obj = new SFSObject();
				GameBoard board = mExtension.getBoard(room.getId());
				
				if(room.isGame() && board==null){
					board = new GameBoard(room.getId(), room.getName());
				}
				
				obj = board.getInfoOfBoard();
				mResultObject.putSFSObject(room.getName(), obj);
			}
		}
		
		send(Commands.LOBBY_HADNLER, mResultObject, user);
	}

}
